Scheduler for WinRT
Customizing the Edit Appointment Dialog

You can easily customize the Edit Appointment Dialog by customizing the EditAppointmentControl.xaml file.

 For reference, here's the markup and code used to create the EditAppointmentControl:

XAML
Copy Code
<UserControl
    x:Class="SchedulerTest3.EditAppointmentControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:SchedulerTest3"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:c1="using:C1.Xaml"
    xmlns:c1datetime="using:C1.Xaml.DateTimeEditors"
    xmlns:Schedule="using:C1.Xaml.Schedule"
    xmlns:res="using:C1.Silverlight.Schedule.Resources"
    FontSize="{ThemeResource ControlContentThemeFontSize}"
    Loaded="EditAppointmentControl_Loaded" x:Name="root" DataContextChanged="OnDataContextChanged"
    mc:Ignorable="d" >
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.ThemeDictionaries>
                <ResourceDictionary x:Key="Default">
                    <SolidColorBrush x:Key="RoundButtonForegroundThemeBrush" Color="#FF24AAD8"/>
                    <SolidColorBrush x:Key="RoundButtonPointerOverBackgroundThemeBrush" Color="#2124AAD8"/>
                </ResourceDictionary>
                <ResourceDictionary x:Key="Light">
                    <SolidColorBrush x:Key="RoundButtonForegroundThemeBrush" Color="#FF24AAD8"/>
                    <SolidColorBrush x:Key="RoundButtonPointerOverBackgroundThemeBrush" Color="#2124AAD8"/>
                </ResourceDictionary>
                <ResourceDictionary x:Key="HighContrast">
                    <SolidColorBrush x:Key="RoundButtonForegroundThemeBrush" Color="#FFFFFFFF"/>
                    <SolidColorBrush x:Key="RoundButtonPointerOverBackgroundThemeBrush" Color="#FF008000"/>
                </ResourceDictionary>
                <ResourceDictionary x:Key="HighContrastBlack">
                    <SolidColorBrush x:Key="RoundButtonForegroundThemeBrush" Color="#FFFFFFFF"/>
                    <SolidColorBrush x:Key="RoundButtonPointerOverBackgroundThemeBrush" Color="#FF1AEBFF"/>
                </ResourceDictionary>
                <ResourceDictionary x:Key="HighContrastWhite">
                    <SolidColorBrush x:Key="RoundButtonForegroundThemeBrush" Color="#FF000000"/>
                    <SolidColorBrush x:Key="RoundButtonPointerOverBackgroundThemeBrush" Color="#FF37006E"/>
                </ResourceDictionary>
            </ResourceDictionary.ThemeDictionaries>
            <SolidColorBrush x:Key="highlightBrush" Color="{ThemeResource SystemColorHotlightColor}"/>
            <Style x:Key="roundButtonStyle" TargetType="Button">
                <Setter Property="MinWidth" Value="0"/>
                <Setter Property="Width" Value="42"/>
                <Setter Property="Height" Value="42"/>
                <Setter Property="Margin" Value="0"/>
                <Setter Property="VerticalAlignment" Value="Bottom"/>
                <Setter Property="Foreground" Value="{ThemeResource RoundButtonForegroundThemeBrush}"/>
                <Setter Property="FontFamily" Value="Segoe UI Symbol"/>
                <Setter Property="FontWeight" Value="Normal"/>
                <Setter Property="FontSize" Value="20"/>
                <Setter Property="AutomationProperties.AutomationId" Value="BackButton"/>
                <Setter Property="AutomationProperties.Name" Value="Back"/>
                <Setter Property="AutomationProperties.ItemType" Value="Navigation Button"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="Button">
                            <Grid x:Name="RootGrid">
                                <Grid >
                                    <Rectangle x:Name="FocusVisualWhite" Margin="-3" IsHitTestVisible="False"
                                           Stroke="{ThemeResource FocusVisualWhiteStrokeThemeBrush}"
                                           StrokeEndLineCap="Square" StrokeDashArray="1,1" Opacity="0" StrokeDashOffset="1.5" />
                                    <Rectangle x:Name="FocusVisualBlack" Margin="-3" IsHitTestVisible="False"
                                           Stroke="{ThemeResource FocusVisualBlackStrokeThemeBrush}"
                                           StrokeEndLineCap="Square" StrokeDashArray="1,1" Opacity="0" StrokeDashOffset="0.5" />
                                    <Ellipse Stroke="{TemplateBinding Foreground}" StrokeThickness="2"
                                         VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/>
                                    <Ellipse x:Name="BackgroundGlyph" Stroke="{TemplateBinding Foreground}" StrokeThickness="2"
                                         Fill="{TemplateBinding Foreground}" Opacity="0"
                                         VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/>
                                    <TextBlock x:Name="NormalGlyph" Text="{TemplateBinding Content}" Foreground="{TemplateBinding Foreground}"
                                           VerticalAlignment="Center" HorizontalAlignment="Center" />
                                    <TextBlock x:Name="ArrowGlyph" Text="{TemplateBinding Content}" Foreground="{ThemeResource BackButtonPressedFore
                                           VerticalAlignment="Center" HorizontalAlignment="Center" />
                                </Grid>
                                <VisualStateManager.VisualStateGroups>
                                    <VisualStateGroup x:Name="CommonStates">
                                        <VisualState x:Name="Normal" />
                                        <VisualState x:Name="PointerOver">
                                            <Storyboard>
                                                <DoubleAnimation Storyboard.TargetName="BackgroundGlyph" Storyboard.TargetProperty="Opacity" To="1"
                                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackgroundGlyph" Storyboard.TargetProperty="Fi
                                                    <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource RoundButtonPointerOverBackgroundThemeB
                                                </ObjectAnimationUsingKeyFrames>
                                            </Storyboard>
                                        </VisualState>
                                        <VisualState x:Name="Pressed">
                                            <Storyboard>
                                                <DoubleAnimation Storyboard.TargetName="BackgroundGlyph" Storyboard.TargetProperty="Opacity" To="1"
                                                <DoubleAnimation Storyboard.TargetName="ArrowGlyph" Storyboard.TargetProperty="Opacity" To="1" Durat
                                                <DoubleAnimation Storyboard.TargetName="NormalGlyph" Storyboard.TargetProperty="Opacity" To="0" Dura
                                            </Storyboard>
                                        </VisualState>
                                        <VisualState x:Name="Disabled">
                                            <Storyboard>
                                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="RootGrid" Storyboard.TargetProperty="Visibilit
                                                    <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                                                </ObjectAnimationUsingKeyFrames>
                                            </Storyboard>
                                        </VisualState>
                                    </VisualStateGroup>
                                    <VisualStateGroup x:Name="FocusStates">
                                        <VisualState x:Name="Focused">
                                            <Storyboard>
                                                <DoubleAnimation Storyboard.TargetName="FocusVisualWhite"
                                                             Storyboard.TargetProperty="Opacity" To="1" Duration="0" />
                                                <DoubleAnimation Storyboard.TargetName="FocusVisualBlack"
                                                             Storyboard.TargetProperty="Opacity" To="1" Duration="0" />
                                            </Storyboard>
                                        </VisualState>
                                        <VisualState x:Name="Unfocused" />
                                        <VisualState x:Name="PointerFocused" />
                                    </VisualStateGroup>
                                </VisualStateManager.VisualStateGroups>
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
            <DataTemplate x:Key="BaseObjectItemPictTextTemplate">
                <Grid Background="Transparent">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>
                    <Border Name="imageBorder" BorderBrush="Black" BorderThickness="1" CompositeMode="MinBlend"
                        Height="18" Width="18" Background="{Binding Brush.Brush}"
                        HorizontalAlignment="Center" VerticalAlignment="Center" Margin="6,2">
                    </Border>
                    <TextBlock Grid.Column="1" Text="{Binding Text}" VerticalAlignment="Center"  />
                </Grid>
            </DataTemplate>
            <res:C1_Schedule_EditAppointment x:Key="C1_Schedule_EditAppointment"/>
        </ResourceDictionary>
    </UserControl.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" MinWidth="320"/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <Rectangle Grid.Column="0" Grid.RowSpan="2">
            <Rectangle.Fill>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#FF5B9E5B" Offset="0.439"/>
                    <GradientStop Color="#FF0A630A" Offset="0.703"/>
                    <GradientStop Color="#FF368136" Offset="0.123"/>
                </LinearGradientBrush>
            </Rectangle.Fill>
        </Rectangle>
        <Rectangle Grid.Column="1" Grid.RowSpan="2" >
            <Rectangle.Fill>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#FF1B4B1B" Offset="0.394"/>
                    <GradientStop Color="#FF407848" Offset="0.048"/>
                    <GradientStop Color="#FF349B34" Offset="0.697"/>
                </LinearGradientBrush>
            </Rectangle.Fill>
        </Rectangle>
        <Grid Grid.Row="0" Grid.Column="0" VerticalAlignment="Center">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <Button x:Name="backButton" Click="backButton_Click" Grid.Column="0" Content="&#xE112;" TabIndex="4"
                ToolTipService.ToolTip="{Binding backButton_ToolTip, Source={StaticResource C1_Schedule_EditAppointment}}"
                Margin="22, 10, 10, 10" VerticalAlignment="Center" Style="{StaticResource roundButtonStyle}" Background="#FF060606" Foreground="Whit
            <TextBlock Margin="5" Text="{Binding Header, ElementName=root}" TextWrapping="NoWrap" TextTrimming="CharacterEllipsis"
                Grid.Column="1" FontSize="18" MaxWidth="240" VerticalAlignment="Center"/>
        </Grid>
        <Grid Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <Rectangle Height="2" Fill="{StaticResource highlightBrush}" Grid.ColumnSpan="3" Margin="30,0,0,0" VerticalAlignment="Bottom" Horizontal
            <TextBox x:Name="subject" TabIndex="0" Padding="2" BorderThickness="0"
                PlaceholderText="{Binding subjectPlaceHolder, Source={StaticResource C1_Schedule_EditAppointment}}"
                Margin="30,0,0,1" Text="{Binding Subject, Mode=TwoWay}" TextChanged="subject_TextChanged" FontSize="18"
                Grid.Column="0" MaxLength="255" IsColorFontEnabled="True" VerticalAlignment="Center"/>
            <Button x:Name="saveButton" Click="saveButton_Click" Grid.Column="1" Content="&#xE105;" TabIndex="1"
                ToolTipService.ToolTip="{Binding saveButton_ToolTip, Source={StaticResource C1_Schedule_EditAppointment}}"
                Margin="10" VerticalAlignment="Center" Style="{StaticResource roundButtonStyle}" Foreground="White"/>
            <Button x:Name="deleteButton" Grid.Column="2" Content="&#xE106;" TabIndex="2"
                c1:CommandExtensions.CommandTarget="{Binding ParentCollection.ParentStorage.ScheduleStorage.Scheduler}"
                c1:CommandExtensions.CommandParameter="{Binding Tag}"
                 c1:CommandExtensions.Command="c1sched:C1Scheduler.DeleteAppointmentCommand"                        
                ToolTipService.ToolTip="{Binding deleteButton_ToolTip1, Source={StaticResource C1_Schedule_EditAppointment}}"
                Margin="10" VerticalAlignment="Center" Style="{StaticResource roundButtonStyle}" Foreground="White"/>
        </Grid>
        <StackPanel Grid.Column="0" Grid.Row="1" Margin="20, 10, 10, 10">
            <!-- dates and times -->
            <TextBlock Margin="5,5,5,0" Text="{Binding startTime, Source={StaticResource C1_Schedule_EditAppointment}}"/>
            <c1datetime:C1DateTimePicker x:Name="startCalendar" Margin="5" TabIndex="5" DateTimeChanged="startCalendar_DateTimeChanged"
                Padding="4" TimeFormat="ShortTime" DateFormat="Short" TimeIncrement="0:15"                
                FirstDayOfWeek="{Binding Path=ParentCollection.ParentStorage.ScheduleStorage.Scheduler.CalendarHelper.WeekStart}" />
            <!-- End -->
            <TextBlock Margin="5,5,5,0" Text="{Binding endTime, Source={StaticResource C1_Schedule_EditAppointment}}"/>
            <c1datetime:C1DateTimePicker x:Name="endCalendar" Margin="5" TabIndex="6"
                Padding="4" DateTimeChanged="endCalendar_DateTimeChanged"
                FirstDayOfWeek="{Binding Path=ParentCollection.ParentStorage.ScheduleStorage.Scheduler.CalendarHelper.WeekStart}"
                TimeFormat="ShortTime" DateFormat="Short" TimeIncrement="0:15"/>
            <!-- All Day -->
            <CheckBox x:Name="chkAllDay" Checked="chkAllDay_Checked" Unchecked="chkAllDay_Unchecked" TabIndex="7"
                Margin="5" IsChecked="{Binding AllDayEvent, Mode=TwoWay}"
                Content="{Binding allDayEvent, Source={StaticResource C1_Schedule_EditAppointment}}"/>
            <!-- location -->
            <TextBox x:Name="location" Margin="5" IsColorFontEnabled="True" TabIndex="8"
                Header="{Binding location, Source={StaticResource C1_Schedule_EditAppointment}}"
                Text="{Binding Location, Mode=TwoWay}" MaxLength="255"/>
            <!-- recurrence -->
            <ComboBox x:Name="howOften" SelectionChanged="howOften_SelectionChanged" TabIndex="9"
                Header="{Binding howOftenComboBoxHeader, Source={StaticResource C1_Schedule_EditAppointment}}"
                MinWidth="140" Margin="5" />
            <StackPanel x:Name="recPanel">
                <CheckBox x:Name="recEndDateSet" Margin="5" Checked="recEndDateSet_Checked"  Unchecked="recEndDateSet_Unchecked" TabIndex="10"
                    Content="{Binding recEndDate, Source={StaticResource C1_Schedule_EditAppointment}}" />
                <c1datetime:C1DateTimePicker x:Name="recEndDate" Margin="5" IsEnabled="{Binding IsChecked, ElementName=recEndDateSet}" TabIndex="11"
                    Padding="4" DateFormat="Short" EditMode="Date" DateTimeChanged="recEndDate_DateTimeChanged"             
                     FirstDayOfWeek="{Binding Path=ParentCollection.ParentStorage.ScheduleStorage.Scheduler.CalendarHelper.WeekStart}" />
            </StackPanel>
            <!-- reminder -->
            <CheckBox x:Name="reminderSet" IsChecked="{Binding ReminderSet, Mode=TwoWay}" Margin="5" TabIndex="12"
                Content="{Binding reminderSet, Source={StaticResource C1_Schedule_EditAppointment}}" />
            <c1datetime:C1TimeEditor x:Name="reminderTime" TabIndex="13"
                Format="TimeSpan" Padding="4" Margin="5" IsEnabled="{Binding Path=IsChecked, ElementName=reminderSet}"
                Increment="00:05" CycleChangesOnBoundaries="False"
                AllowNull="False" Minimum="0:00" Maximum="14.00:00" />
            <!-- other props -->
            <ComboBox x:Name="status" TabIndex="14"
                ItemTemplate="{StaticResource BaseObjectItemPictTextTemplate}"
                ItemsSource="{Binding ParentCollection.ParentStorage.ScheduleStorage.StatusStorage.Statuses}"
                SelectedItem="{Binding Path=BusyStatus, Mode=TwoWay}"
                Header="{Binding showTimeAs, Source={StaticResource C1_Schedule_EditAppointment}}"
                MinWidth="140" Padding="0" Margin="5" />
            <ComboBox Grid.Row="1" TabIndex="15" ItemTemplate="{StaticResource BaseObjectItemPictTextTemplate}"
                ItemsSource="{Binding ParentCollection.ParentStorage.ScheduleStorage.LabelStorage.Labels}"
                SelectedItem="{Binding Path=Label, Mode=TwoWay}"
                Header="{Binding label, Source={StaticResource C1_Schedule_EditAppointment}}"
                MinWidth="140" Padding="0" Margin="5" />
            <CheckBox IsChecked="{Binding Path=Private, Mode=TwoWay}" Margin="5" TabIndex="16"
                Content="{Binding private_, Source={StaticResource C1_Schedule_EditAppointment}}" />
        </StackPanel>
        <TextBox x:Name="body" Text="{Binding Body, Mode=TwoWay}" Grid.Column="1" Grid.Row="1" TextWrapping="Wrap" TabIndex="3"
            AcceptsReturn="True" IsSpellCheckEnabled="True" IsColorFontEnabled="True" ScrollViewer.HorizontalScrollMode="Disabled"
            ScrollViewer.VerticalScrollBarVisibility="Auto" BorderThickness="0" Margin="30,0,0,0" PlaceholderText="Add text" Foreground="#FFD6FFD0">
            <TextBox.Background>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#FF9DEE68" Offset="0.345"/>
                    <GradientStop Color="#FF68914D" Offset="0.79"/>
                    <GradientStop Color="#FF4C8029" Offset="0.103"/>
                </LinearGradientBrush>
            </TextBox.Background>
        </TextBox>
    </Grid>
</UserControl>

C#
Copy Code
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using C1.C1Schedule;
using C1.Xaml.Schedule;
using C1.Xaml;
using Windows.UI;
// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236
namespace SchedulerTest3
{
    public sealed partial class EditAppointmentControl : UserControl
    {
        #region ** fields
        private C1FullscreenDialog _parentWindow = null;
        private Appointment _appointment;
        private C1Scheduler _scheduler;
        private bool _isLoaded = false;
        private TimeSpan _defaultStart;
        private TimeSpan _defaultDuration;
        private bool _updatingRecurrence = false;
        #endregion
        //-----------------------------------------------------------------------------------
        #region ** initialization
        /// <summary>
        /// Creates the new instance of the <see cref="EditAppointmentControl"/> class.
        /// </summary>
        public EditAppointmentControl()
        {
            this.InitializeComponent();
            // fill recurrence combo
            List<string> recTypes = new List<string>();
            recTypes.Add(C1.Silverlight.Schedule.Resources.C1_Schedule_EditAppointment.recOnce);
            recTypes.Add(C1.Silverlight.Schedule.Resources.C1_Schedule_EditAppointment.recDaily);
            recTypes.Add(C1.Silverlight.Schedule.Resources.C1_Schedule_EditAppointment.recWeekdays);
            recTypes.Add(C1.Silverlight.Schedule.Resources.C1_Schedule_EditAppointment.recMonday);
            recTypes.Add(C1.Silverlight.Schedule.Resources.C1_Schedule_EditAppointment.recTuesday);
            recTypes.Add(C1.Silverlight.Schedule.Resources.C1_Schedule_EditAppointment.recWeekly);
            recTypes.Add(C1.Silverlight.Schedule.Resources.C1_Schedule_EditAppointment.recMonthly);
            recTypes.Add(C1.Silverlight.Schedule.Resources.C1_Schedule_EditAppointment.recYearly);
            howOften.ItemsSource = recTypes;
        }
        private void OnDataContextChanged(FrameworkElement sender, DataContextChangedEventArgs args)
        {
            if (DataContext != null)
            {
                _appointment = DataContext as Appointment;
                _defaultStart = _appointment.AllDayEvent ? TimeSpan.FromHours(8) : _appointment.Start.TimeOfDay;
                _defaultDuration = _appointment.AllDayEvent ? TimeSpan.FromMinutes(30) : _appointment.Duration;
                if (_appointment != null)
                {
                    if (_appointment.ParentCollection != null)
                    {
                        _scheduler = _appointment.ParentCollection.ParentStorage.ScheduleStorage.Scheduler;
                        if (_appointment.AllDayEvent)
                        {
                            _defaultStart = _scheduler.CalendarHelper.StartDayTime;
                            _defaultDuration = _scheduler.CalendarHelper.Info.TimeScale;
                        }
                    }
                    UpdateWindowHeader();
                    UpdateRecurrenceState();
                    reminderTime.Value = _appointment.ReminderTimeBeforeStart;
                    UpdateCalendars();
                    if (_appointment.AllDayEvent)
                    {
                        startCalendar.EditMode = endCalendar.EditMode = C1.Xaml.DateTimeEditors.C1DateTimePickerEditMode.Date;
                    }
                    else
                    {
                        startCalendar.EditMode = endCalendar.EditMode = C1.Xaml.DateTimeEditors.C1DateTimePickerEditMode.DateTime;
                    }
                }
            }
        }
        private void EditAppointmentControl_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            if (!_isLoaded)
            {
                _parentWindow = (C1FullscreenDialog)VTreeHelper.GetParentOfType(this, typeof(C1FullscreenDialog));
                if (_parentWindow != null && _appointment != null)
                {
                    _parentWindow.Unloaded += _parentWindow_Unloaded;
                    _isLoaded = true;
                }
            }
            subject.Focus(Windows.UI.Xaml.FocusState.Programmatic);
        }
        void _parentWindow_Unloaded(object sender, RoutedEventArgs e)
        {
            _parentWindow.Unloaded -= _parentWindow_Unloaded;
            DataContext = null;
            _scheduler = null;
            _appointment = null;
            _parentWindow = null;
        }
        #endregion
        //-----------------------------------------------------------------------------------
        #region ** object model
        /// <summary>
        /// Gets or sets an <see cref="Appointment"/> object representing current DataContext.
        /// </summary>
        public Appointment Appointment
        {
            get
            {
                return _appointment;
            }
            set
            {
                _appointment = value;
                if (_parentWindow != null)
                {
                    _parentWindow.Content =
                    _parentWindow.DataContext = value;
                }
                DataContext = value;
                if (_appointment != null)
                {
                    UpdateWindowHeader();
                    UpdateRecurrenceState();
                }
            }
        }
        /// <summary>
        /// Gets a <see cref="String"/> value which can be used as an Appointment window header.
        /// </summary>
        public string Header
        {
            get { return (string)GetValue(HeaderProperty); }
            private set { SetValue(HeaderProperty, value); }
        }
        /// <summary>
        /// Identifies the <see cref="Header"/> dependency property.
        /// </summary>
        private static readonly DependencyProperty HeaderProperty =
            DependencyProperty.Register("Header", typeof(string),
            typeof(EditAppointmentControl), new PropertyMetadata(string.Empty));
        #endregion
        //-----------------------------------------------------------------------------------
        #region ** recurrence properties
        private void UpdateRecurrenceState()
        {
            if (_appointment == null || _updatingRecurrence)
            {
                return;
            }
            if (_appointment.RecurrenceState == RecurrenceStateEnum.NotRecurring)
            {
                recPanel.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                howOften.IsEnabled = true;
                howOften.SelectedIndex = 0;
            }
            else
            {
                RecurrencePattern pattern = _appointment.GetRecurrencePattern();
                switch (pattern.RecurrenceType)
                {
                    case RecurrenceTypeEnum.Daily:
                        howOften.SelectedIndex = 1;
                        break;
                    case RecurrenceTypeEnum.Workdays:
                        howOften.SelectedIndex = 2;
                        break;
                    case RecurrenceTypeEnum.Weekly:
                        WeekDaysEnum mask = pattern.DayOfWeekMask;
                        if ((mask & WeekDaysEnum.Monday) == WeekDaysEnum.Monday
                            && (mask & WeekDaysEnum.Wednesday) == WeekDaysEnum.Wednesday
                            && (mask & WeekDaysEnum.Friday) == WeekDaysEnum.Friday
                            && (mask & WeekDaysEnum.Tuesday) != WeekDaysEnum.Tuesday)
                        {
                            howOften.SelectedIndex = 3;
                        }
                        else if ((mask & WeekDaysEnum.Tuesday) == WeekDaysEnum.Tuesday && (mask & WeekDaysEnum.Thursday) == WeekDaysEnum.Thursday)
                        {
                            howOften.SelectedIndex = 4;
                        }
                        else
                        {
                            howOften.SelectedIndex = 5;
                        }
                        break;
                    case RecurrenceTypeEnum.Monthly:
                        howOften.SelectedIndex = 6;
                        break;
                    case RecurrenceTypeEnum.Yearly:
                        howOften.SelectedIndex = 7;
                        break;
                }
                if (_appointment.RecurrenceState == RecurrenceStateEnum.Master)
                {
                    recPanel.Visibility = Windows.UI.Xaml.Visibility.Visible;
                    howOften.IsEnabled = true;
                    recEndDate.DateTime = pattern.PatternEndDate;
                    recEndDateSet.IsChecked = !pattern.NoEndDate;
                }
                else
                {
                    // occurrence
                    recPanel.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                    howOften.IsEnabled = false;
                }
            }
        }
        private void howOften_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (_appointment == null)
            {
                return;
            }
            _updatingRecurrence = true;
            if (howOften.SelectedIndex == 0)
            {
                _appointment.ClearRecurrencePattern();
            }
            else
            {
                RecurrencePattern pattern = _appointment.GetRecurrencePattern();
                switch (howOften.SelectedIndex)
                {
                    case 1:
                        pattern.RecurrenceType = RecurrenceTypeEnum.Daily;
                        break;
                    case 2:
                        pattern.RecurrenceType = RecurrenceTypeEnum.Workdays;
                        break;
                    case 3:
                        pattern.RecurrenceType = RecurrenceTypeEnum.Weekly;
                        pattern.DayOfWeekMask = WeekDaysEnum.Monday | WeekDaysEnum.Wednesday | WeekDaysEnum.Friday;
                        break;
                    case 4:
                        pattern.RecurrenceType = RecurrenceTypeEnum.Weekly;
                        pattern.DayOfWeekMask = WeekDaysEnum.Tuesday | WeekDaysEnum.Thursday;
                        break;
                    case 5:
                        pattern.RecurrenceType = RecurrenceTypeEnum.Weekly;
                        pattern.DayOfWeekMask = (WeekDaysEnum)Enum.Parse(typeof(WeekDaysEnum), Enum.GetName(typeof(DayOfWeek), _appointment.Start.DayOfWeek), true);
                        break;
                    case 6:
                        pattern.RecurrenceType = RecurrenceTypeEnum.Monthly;
                        pattern.DayOfMonth = _appointment.Start.Day;
                        break;
                    case 7:
                        pattern.RecurrenceType = RecurrenceTypeEnum.Yearly;
                        pattern.DayOfMonth = _appointment.Start.Day;
                        pattern.MonthOfYear = _appointment.Start.Month;
                        break;
                }
            }
            _updatingRecurrence = false;
            UpdateRecurrenceState();
            UpdateCalendars();
        }
        private void recEndDateSet_Unchecked(object sender, RoutedEventArgs e)
        {
            if (_appointment != null && _appointment.RecurrenceState == RecurrenceStateEnum.Master)
            {
                RecurrencePattern pattern = _appointment.GetRecurrencePattern();
                pattern.NoEndDate = true;
            }
        }
        private void recEndDateSet_Checked(object sender, RoutedEventArgs e)
        {
            if (_appointment != null && _appointment.RecurrenceState == RecurrenceStateEnum.Master)
            {
                RecurrencePattern pattern = _appointment.GetRecurrencePattern();
                pattern.NoEndDate = false;
                pattern.PatternEndDate = recEndDate.DateTime.Value;
            }
        }
        private void recEndDate_DateTimeChanged(object sender, object e)
        {
            if (_appointment != null && _appointment.RecurrenceState == RecurrenceStateEnum.Master)
            {
                RecurrencePattern pattern = _appointment.GetRecurrencePattern();
                pattern.PatternEndDate = recEndDate.DateTime.Value;
            }
        }
        #endregion
        //-----------------------------------------------------------------------------------
        #region ** times
        private void startCalendar_DateTimeChanged(object sender, object e)
        {
            if (_appointment != null)
            {
                _appointment.Start = startCalendar.DateTime.Value;
                if (_appointment.RecurrenceState == RecurrenceStateEnum.Master)
                {
                    RecurrencePattern pattern = _appointment.GetRecurrencePattern();
                    pattern.PatternStartDate = startCalendar.DateTime.Value;
                    pattern.StartTime = _appointment.Start;
                }
                UpdateCalendars();
            }
        }
        private void chkAllDay_Checked(object sender, RoutedEventArgs e)
        {
            if (_appointment.RecurrenceState == RecurrenceStateEnum.Master)
            {
                RecurrencePattern pattern = _appointment.GetRecurrencePattern();
                pattern.StartTime = _appointment.Start;
                pattern.Duration = _appointment.Duration;
            }
            startCalendar.EditMode = endCalendar.EditMode = C1.Xaml.DateTimeEditors.C1DateTimePickerEditMode.Date;
            UpdateWindowHeader();
            UpdateCalendars();
        }
        private void chkAllDay_Unchecked(object sender, RoutedEventArgs e)
        {
            _appointment.Start = _appointment.Start.Add(_defaultStart);
            _appointment.Duration = _defaultDuration;
            if (_appointment.RecurrenceState == RecurrenceStateEnum.Master)
            {
                RecurrencePattern pattern = _appointment.GetRecurrencePattern();
                pattern.StartTime = _appointment.Start;
                pattern.Duration = _appointment.Duration;
            }
            startCalendar.EditMode = endCalendar.EditMode = C1.Xaml.DateTimeEditors.C1DateTimePickerEditMode.DateTime;
            UpdateWindowHeader();
            UpdateCalendars();
        }
        private void endCalendar_DateTimeChanged(object sender, object e)
        {
            if (_appointment != null)
            {
                DateTime end = endCalendar.DateTime.Value;
                if (_appointment.AllDayEvent)
                {
                    end = end.AddDays(1);
                }
                if (end < Appointment.Start)
                {
                    endCalendar.BorderBrush = endCalendar.Foreground = new SolidColorBrush(Colors.Red);
                    endCalendar.BorderThickness = new Thickness(2);
                    ToolTipService.SetToolTip(endCalendar, C1.Silverlight.Schedule.Resources.C1_Schedule_Exceptions.StartEndValidationFailed);
                    saveButton.IsEnabled = false;
                }
                else
                {
                    _appointment.End = end;
                    if (!saveButton.IsEnabled)
                    {
                        saveButton.IsEnabled = true;
                        endCalendar.ClearValue(Control.ForegroundProperty);
                        endCalendar.ClearValue(Control.BorderBrushProperty);
                        endCalendar.ClearValue(Control.BorderThicknessProperty);
                        endCalendar.ClearValue(ToolTipService.ToolTipProperty);
                    }
                }
                if (_appointment.RecurrenceState == RecurrenceStateEnum.Master)
                {
                    RecurrencePattern pattern = _appointment.GetRecurrencePattern();
                    pattern.StartTime = _appointment.Start;
                    pattern.Duration = _appointment.Duration;
                }
            }
        }
        private void UpdateCalendars()
        {
            if (_appointment.RecurrenceState == RecurrenceStateEnum.Master)
            {
                RecurrencePattern pattern = _appointment.GetRecurrencePattern();
                startCalendar.DateTime = pattern.StartTime;
                DateTime end = pattern.EndTime;
                if (_appointment.AllDayEvent)
                {
                    end = end.AddDays(-1);
                }
                endCalendar.DateTime = end;
            }
            else
            {
                startCalendar.DateTime = _appointment.Start;
                DateTime end = _appointment.End;
                if (_appointment.AllDayEvent)
                {
                    end = end.AddDays(-1);
                }
                endCalendar.DateTime = end;
            }
            if (!saveButton.IsEnabled)
            {
                saveButton.IsEnabled = true;
                endCalendar.ClearValue(Control.BackgroundProperty);
                endCalendar.ClearValue(Control.ForegroundProperty);
                endCalendar.ClearValue(Control.BorderBrushProperty);
                endCalendar.ClearValue(Control.BorderThicknessProperty);
                endCalendar.ClearValue(ToolTipService.ToolTipProperty);
            }
        }
        #endregion
        //-----------------------------------------------------------------------------------
        #region ** misc props
        private void UpdateWindowHeader()
        {
            string result;
            string subject = string.Empty;
            bool allDay = false;
            if (_appointment != null)
            {
                subject = _appointment.Subject;
                allDay = chkAllDay.IsChecked.Value;
            }
            if (String.IsNullOrEmpty(subject))
            {
                subject = C1.Silverlight.Schedule.Resources.C1_Schedule_EditAppointment.Untitled;
            }
            if (allDay)
            {
                result = C1.Silverlight.Schedule.Resources.C1_Schedule_EditAppointment.Event + " - " + subject;
            }
            else
            {
                result = C1.Silverlight.Schedule.Resources.C1_Schedule_EditAppointment.Appointment + " - " + subject;
            }
            Header = result;
        }
        private void subject_TextChanged(object sender, TextChangedEventArgs e)
        {
            subject.GetBindingExpression(TextBox.TextProperty).UpdateSource();
            UpdateWindowHeader();
        }
        #endregion
        //-----------------------------------------------------------------------------------
        #region ** navigation
        private void saveButton_Click(object sender, RoutedEventArgs e)
        {
            _appointment.ReminderTimeBeforeStart = reminderTime.Value.Value;
            subject.Focus(Windows.UI.Xaml.FocusState.Programmatic);
            location.GetBindingExpression(TextBox.TextProperty).UpdateSource();
            body.GetBindingExpression(TextBox.TextProperty).UpdateSource();
            _parentWindow.DialogResult = MessageBoxResult.OK;
        }
        private void backButton_Click(object sender, RoutedEventArgs e)
        {
            _parentWindow.DialogResult = MessageBoxResult.Cancel;
        }
#pragma warning disable 1591
        protected override void OnKeyDown(Windows.UI.Xaml.Input.KeyRoutedEventArgs e)
        {
            if (e.Key == Windows.System.VirtualKey.Escape)
            {
                backButton_Click(null, null);
            }
            else if (e.Key == Windows.System.VirtualKey.S && KeyboardUtil.Ctrl)
            {
                saveButton_Click(null, null);
            }
            else if (e.Key == Windows.System.VirtualKey.D && KeyboardUtil.Ctrl)
            {
                _scheduler.DeleteAppointment(_appointment.Tag as Appointment);
            }
            base.OnKeyDown(e);
        }
#pragma warning restore 1591
        #endregion
    }
}

Add a new UserControl to your application:

  1. Right-click your application name and select Add | New Item from the context menu.
  2. Select User Control from the Add New Item dialog.
  3. Name your new User Control EditAppointmentControl and click OK. The control will be added to your application.

Open your EditAppointmentControl.xaml file and add the XAML markup from the top of the page. You can edit this markup to customize the New Appointment Dialog. Add the code to the EditAppointmentControl.xaml.cs file.

Now that you have a custom dialog, define a DataTemplate in your Page's resources that will load the user control:

XAML
Copy Code
<Page.Resources>
    <DataTemplate x:Key="customEditAppointmentTemplate">
        <local:EditAppointmentControl/>
    </DataTemplate>
</Page.Resources>

Lastly, set the EditAppointmentTemplate property on the C1Scheduler control.

XAML
Copy Code
<Schedule:C1Scheduler x:Name="sched1" EditAppointmentTemplate="{StaticResource customEditAppointmentTemplate}" />

You're done! When you open the Edit Appointment Dialog, your customization will be apparent .

 

 


Copyright (c) GrapeCity, inc. All rights reserved.

Product Support Forum  |  Documentation Feedback